﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp5_StackPanel
{
    /// <summary>
    /// CommandWindow.xaml 的交互逻辑
    /// </summary>
    public partial class CommandWindow : Window
    {
        public static RoutedCommand MyCommand = new RoutedCommand();
        public CommandWindow()
        {
            InitializeComponent();
            CommandBinding cb = new CommandBinding(MyCommand, ExecuteMyCommand, CanExecuteMyCommand);
            this.CommandBindings.Add(cb);
            KeyGesture kg = new KeyGesture(Key.M, ModifierKeys.Control);
            InputBinding ib = new InputBinding(MyCommand, kg);
            this.InputBindings.Add(ib);
        }

        private void HelpCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }

        private void HelpExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("有什么可以帮你？");
        }

        private void CanExecuteMyCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }

        private void ExecuteMyCommand(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("这是你自己的命令。");
        }
    }
}
